/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sk.itat.wicket;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.PasswordTextField;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.validation.validator.EmailAddressValidator;
import org.apache.wicket.validation.validator.StringValidator;

/**
 *
 * @author opteron1441
 */
public final class RegistrationPage extends BasePage {

    public RegistrationPage() {
        super();

        Uzivatel uzivatel = new Uzivatel();
        CompoundPropertyModel userModel = new CompoundPropertyModel(uzivatel);
        Form form = new UserProfileForm("regForm", userModel);

        TextField firstNameFld = new TextField("firstName");
        firstNameFld.setRedirect(true);

        TextField lastNameFld = new TextField("lastName");
        lastNameFld.setRequired(true);

        TextField logFld = new TextField("login");
        logFld.setRequired(true);

        PasswordTextField passFld = new PasswordTextField("heslo");
        passFld.setRequired(true);
        passFld.setResetPassword(false);
        passFld.add(StringValidator.minimumLength(5));

        TextField adressFld = new TextField("adresa");
        adressFld.setRequired(true);

        TextField telFld = new TextField("telCislo");
        TextField emailFld = new TextField("email");
        emailFld.setRequired(true);
        emailFld.add(EmailAddressValidator.getInstance());

        TextField spolocnostFld = new TextField("spolocnost");
        DropDownChoice countries = new DropDownChoice("krajina", Arrays.asList(new String[]{"Slovensko", "Polsko", "Ceska republika", "Madarsko"}));

        form.add(firstNameFld);
        form.add(lastNameFld);
        form.add(logFld);
        form.add(passFld);
        form.add(adressFld);
        form.add(telFld);
        form.add(emailFld);
        form.add(spolocnostFld);
        form.add(countries);

        add(new HeaderPanel("mainNavigation", "Registration"));
        add(form);
        add(new FeedbackPanel("errors"));
    }

    public class UserProfileForm extends Form {

        public UserProfileForm(String id, IModel model) {
            super(id, model);

        }

        @Override
        protected void onSubmit() {
            Uzivatel person = (Uzivatel) getModelObject();
            int iD = Application.get().getZoznam().size();
            person.setId(iD);
            Application.get().getZoznam().add(person);

            setResponsePage(new WelcomePage(person));

        }
    }
}
